<?php
require $_SERVER['DOCUMENT_ROOT'].'/../_core/common.php';

$db = new DB('news');

$category_array = array();
//查询一级栏目
$top_category_sql = 'select id,title from categories where top_id=0 and is_del=1 order by orders desc,id asc';
$top_category_rs = $db->query($top_category_sql)->getAll();
foreach($top_category_rs as $k=>$top){
	//查询二级
	$category_sql = 'select id,title from categories where top_id='.$top['id'].' and is_del=1 order by orders desc,id asc';
	$category_rs = $db->query($category_sql)->getAll();
	
	$category_array[ $k ]['id'] = $top['id'];
	$category_array[ $k ]['title'] = $top['title'];
	$category_array[ $k ]['child'] = $category_rs;
}

$html = '';
foreach($category_array as $category){
	$html .= '<li><span class="folder"><a href="/admin/news/news_lists.php?category_id='.$category['id'].'">'.$category['title'].'</a></span>';
	if( !empty($category['child']) ){
		$html .= '<ul>';
		foreach($category['child'] as $child){
			$html .= '<li><span class="folder"><a href="/admin/news/news_lists.php?category_id='.$child['id'].'">'.$child['title'].'</a></span></li>';
		}
		$html .= '</ul>';
	}
	$html .= '</li>';
}
echo $html;